package net.liteheaven.xblib.common.ui;

import android.graphics.Rect;
import android.view.View;
import android.widget.ListView;


/**
 * 
 * ListView工具类 
 * @author  LiangYu
 * @data:  2015-3-26 下午3:38:34 
 * @version:  V1.0
 */
public class ListViewUtil {
	
	public static boolean isListViewAtBottom(ListView view){
		
		boolean ret = false;
		int firstVisiblePosition = view.getFirstVisiblePosition();
		int lastVisiblePosition = view.getLastVisiblePosition();

		if (lastVisiblePosition == (view.getCount() - 1)) {
			
			Rect rect = new Rect();
			View child = view.getChildAt(lastVisiblePosition - firstVisiblePosition);
			boolean visible = child.getGlobalVisibleRect(rect);
			if (visible && child.getHeight() == rect.height()) {
				ret = true;
			}
		}
		return ret;
	}
	
	public static boolean isListViewAtTop(ListView view){
		
		boolean ret = false;
		int firstVisiblePosition = view.getFirstVisiblePosition();
		
		if (firstVisiblePosition == 0) {
			
			Rect rect = new Rect();
			View child = view.getChildAt(0);
			boolean visible = child.getGlobalVisibleRect(rect);
			if (visible && child.getHeight() == rect.height()) {
				ret = true;
			}
		}
		return ret;
	}
}

